
if ability_respawn_hero == nil then ability_respawn_hero = class({}) end

    function ability_respawn_hero:GetBehavior()
        return DOTA_ABILITY_BEHAVIOR_UNIT_TARGET + DOTA_ABILITY_BEHAVIOR_HIDDEN + DOTA_ABILITY_BEHAVIOR_POINT + DOTA_ABILITY_BEHAVIOR_CHANNELLED
    end

    function ability_respawn_hero:GetAbilityType()
        return DOTA_ABILITY_TYPE_ULTIMATE
    end

    function ability_respawn_hero:IsHiddenAbilityCastable()
        return true
    end

    function ability_respawn_hero:IsHidden()
        return true
    end

    function ability_respawn_hero:GetChannelTime()
        self.cast_time=self:GetSpecialValueFor("cast_time")
        self.cast_time_rate=self:GetSpecialValueFor("cast_time_rate")
        if IsServer() then
            local lv=self:GetCaster():GetOwner():GetLevel()
            self.cast_time=self.cast_time*self.cast_time_rate^lv
        else
            local playerInfoTable= CustomNetTables:GetTableValue("player_info", "all")
            for _,playerInfo in pairs(playerInfoTable) do
                if playerInfo.teamId==self:GetCaster():GetTeamNumber() then
                    return self.cast_time*self.cast_time_rate^playerInfo.heroLv
                end
            end
        end
        return self.cast_time
    end

    function ability_respawn_hero:OnChannelFinish( bInterrupted )
        if IsServer() then
            ParticleManager:DestroyParticle( self.particle, true )
            ParticleManager:DestroyParticle( self.particle2, true )
            local hero=self:GetCaster():GetOwner()
            local courier=self:GetCaster()
            if bInterrupted==true then
                self.interruptTime=self.interruptTime or 0
                if ((self.interruptTime)<(self.cast_time)) then
                    self.interruptTime=self.interruptTime+(GameRules:GetGameTime()-self.startTime)
                    Courier:RespawnHero(hero)
                    return
                end
            end
            if  hero:IsAlive()~=true and courier:IsAlive()==true then
                Courier:Hide(courier)
                Timers:CreateTimer(30*FrameTime(),function ()
                    Hero:SpawnToRandomPos(hero)
                    Hero:CenterCamera(hero,1*FrameTime(),24*FrameTime())
                    PlayerResource:NewSelection(hero:GetPlayerID(), hero)
                end)
            end
        end
    end

    function ability_respawn_hero:OnSpellStart()
        --print("OnSpellStart...finish.!!!!")
        if IsServer() then
            self.startTime=GameRules:GetGameTime()
            local caster = self:GetCaster()
            local point = self:GetCursorPosition()
            local target=caster:GetOwner()
            local color=GameRules.G.teamColorList[target:GetTeamNumber()]

            local particle2=ParticleManager:CreateParticle(ParticleNames.spawn_hero2, PATTACH_OVERHEAD_FOLLOW, caster)
            ParticleManager:SetParticleControl(particle2,  0, caster:GetAbsOrigin())
            ParticleManager:SetParticleControl(particle2, 60, Vector(color[1] ,color[2],color[3]))
            ParticleManager:SetParticleControl(particle2, 61, Vector(color[1] ,color[2],color[3]))
            self.particle2=particle2

            local particle = ParticleManager:CreateParticle(ParticleNames.spawn_hero, PATTACH_OVERHEAD_FOLLOW, caster)
            ParticleManager:SetParticleControl(particle,  0, caster:GetAbsOrigin())
            ParticleManager:SetParticleControl(particle, 1, Vector(point.x,point.y,point.z))
            ParticleManager:SetParticleControl(particle, 60, Vector(color[1] ,color[2],color[3]))
            ParticleManager:SetParticleControl(particle, 61, Vector(color[1] ,color[2],color[3]))
            self.particle=particle

            caster:EmitSound(SoundsNames.spawn_hero)
            PlayerResource:NewSelection(target:GetPlayerID(), caster)
        end
    end